
package com.gs.gms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gs.gms.common.exceptions.GmsApplicationException;
import com.gs.gms.dao.UserConnectionDao;
import com.gs.gms.dao.UserDao;
import com.gs.gms.model.dto.UserDto;
import com.gs.gms.model.entity.User;
import com.gs.gms.service.UserService;
import com.gs.gms.util.conerter.GenericConverter;

/**
 * @author Sabuj Das
 *
 */
@Service
@Transactional
public class UserServiceimpl implements UserService {

	@Autowired private UserDao userDao;
	@Autowired private UserConnectionDao userConnectionDao;
	
	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=false)
	public long registerUser(UserDto userDto) throws GmsApplicationException {
		if(null == userDto)
			throw new GmsApplicationException("Input is null");
		User user = null;
		try {
			user = GenericConverter.convert(userDto);
			if(new Long(0).equals(user.getUserId()))
				user.setUserId(null);
			user = userDao.saveUser(user);
			return user.getUserId();
		} catch (Exception e) {
			e.printStackTrace();
			throw new GmsApplicationException(e);
		}
		
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=true)
	public List<UserDto> getAllConnectedUsers(String userName)
			throws GmsApplicationException {
		// TODO Auto-generated method stub
		return null;
	}

}
